package com.empire.module.sporttery.controller.admin.football500rangzhiim;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.CommonResult;
import com.empire.framework.common.util.object.BeanUtils;
import static com.empire.framework.common.pojo.CommonResult.success;

import com.empire.framework.excel.core.util.ExcelUtils;

import com.empire.framework.apilog.core.annotation.ApiAccessLog;
import static com.empire.framework.apilog.core.enums.OperateTypeEnum.*;

import com.empire.module.sporttery.controller.admin.football500rangzhiim.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500rangzhiim.Football500RangzhiImDO;
import com.empire.module.sporttery.service.football500rangzhiim.Football500RangzhiImService;

@Tag(name = "管理后台 - 让球实时")
@RestController
@RequestMapping("/sporttery/football500-rangzhi-im")
@Validated
public class Football500RangzhiImController {

    @Resource
    private Football500RangzhiImService football500RangzhiImService;

    @PostMapping("/create")
    @Operation(summary = "创建让球实时")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-rangzhi-im:create')")
    public CommonResult<Integer> createFootball500RangzhiIm(@Valid @RequestBody Football500RangzhiImSaveReqVO createReqVO) {
        return success(football500RangzhiImService.createFootball500RangzhiIm(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新让球实时")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-rangzhi-im:update')")
    public CommonResult<Boolean> updateFootball500RangzhiIm(@Valid @RequestBody Football500RangzhiImSaveReqVO updateReqVO) {
        football500RangzhiImService.updateFootball500RangzhiIm(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除让球实时")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('sporttery:football500-rangzhi-im:delete')")
    public CommonResult<Boolean> deleteFootball500RangzhiIm(@RequestParam("id") Integer id) {
        football500RangzhiImService.deleteFootball500RangzhiIm(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得让球实时")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-rangzhi-im:query')")
    public CommonResult<Football500RangzhiImRespVO> getFootball500RangzhiIm(@RequestParam("id") Integer id) {
        Football500RangzhiImDO football500RangzhiIm = football500RangzhiImService.getFootball500RangzhiIm(id);
        return success(BeanUtils.toBean(football500RangzhiIm, Football500RangzhiImRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得让球实时分页")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-rangzhi-im:query')")
    public CommonResult<PageResult<Football500RangzhiImRespVO>> getFootball500RangzhiImPage(@Valid Football500RangzhiImPageReqVO pageReqVO) {
        PageResult<Football500RangzhiImDO> pageResult = football500RangzhiImService.getFootball500RangzhiImPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, Football500RangzhiImRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出让球实时 Excel")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-rangzhi-im:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportFootball500RangzhiImExcel(@Valid Football500RangzhiImPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<Football500RangzhiImDO> list = football500RangzhiImService.getFootball500RangzhiImPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "让球实时.xls", "数据", Football500RangzhiImRespVO.class,
                        BeanUtils.toBean(list, Football500RangzhiImRespVO.class));
    }

}